#!/usr/bin/env python
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.2')

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
from model import CourseM
from model import GeneralM

class coursePage(webapp.RequestHandler):
    def get(self):
        user = users.get_current_user()
        if user:
            viewVals = GeneralM.getViewVals()
            viewVals['courses'] = map(CourseM.course2DictWith, CourseM.getCourses())
            if len(viewVals['courses']) == 0: 
                viewVals['courses'] = None
            self.response.out.write(template.render('view/allCourses.djhtml', viewVals))
        else:
            self.redirect("/login")
            
application = webapp.WSGIApplication([(r'.*', coursePage)],debug=True)

def main():
    run_wsgi_app(application)
    
if __name__ == '__main__':
    main()